
$(function(){
	
	getInfoByEvalNum();
	
})

function getInfoByEvalNum(){
	var userId = $('#userId').val();
	var evalNum = $('#evalNum').val();
	$.ajax({
		type : "POST",
		url : "evalReportInfo/getCdnReport",
		data : {
			'evalNum':evalNum, 
			'userId': userId,
		},
		traditional: true,
		dataType : "json",
		success : function(data) {
			fillFormData('#queryForm', data.data);
			//fillFormData('#queryForm', data.cdnMolData);
			var houseData = data.houseData;
			if(null != houseData){
				setHouseBody(houseData);
			}
			var gbpsData = data.gbpsData;
			if(null != gbpsData){
				setGbpsData(gbpsData);
			}
			var icpData = data.icpData;
			if(null != icpData){
				setIcpData(icpData);
			}
		},
		error : function(data) {
			layer.closeAll();
		}
	});
}

function setHouseBody(data){
	if(data && data.length > 0){
		var nodeNum = data.length;
		$('input[name="nodeNum"]').val(nodeNum);
		var houseHtml = ''; // 节点机房信息
		for(var i=0; i<data.length; i++){
			var nodeName = 'houseList[' + i + '].nodeName';
			var houseAddr = 'houseList[' + i + '].houseAddr';
			houseHtml += '<tr>'
				+ '<td>'
				+ '<span>'+ (i+1) +')</span>'
				+ '</td>'
				+ '<td>'
				+ '<input type="text" class="form-control input-sm" name="'+nodeName+'" value="'+data[i].nodeName+'" readonly/>'
				+ '<span>：</span>'
				+ '</td>'
				+ '<td>'
				+ '<input type="text" class="form-control input-sm" name="'+houseAddr+'" value="'+data[i].houseAddr+'" readonly/>'
				+ '</td>'
				+ '</tr>';
		}
		$('#node_house_tbody').html(houseHtml);
	}
}

function setGbpsData(data){
	if(data && data.length > 0){
		var html = ''; // 节点部署省份
		for(var i=0; i<data.length; i++){
			var province = 'gbpsList[' + i + '].province';
			var type = 'gbpsList[' + i + '].type';
			var gbps = 'gbpsList[' + i + '].gbps';
			html += '<tr>'
				+ '<td>'
				+ '<span>'+ (i+1) +')</span>'
				+ '</td>'
				+ '<td>'
				+ '<input type="text" class="form-control input-sm" name="'+province+'" value="'+data[i].province+'" readonly/>'
				+ '<span>：</span>'
				+ '</td>'
				+ '<td>'
				+ '<input type="text" class="form-control input-sm" name="'+type+'" value="'+data[i].type+'" readonly/>'
				+ '<span>，</span>'
				+ '</td>'
				+ '<td>'
				+ '<input type="text" class="form-control input-sm" name="'+gbps+'" value="'+data[i].gbps+'Gbps" readonly/>'
				+ '</td>'
				+ '</tr>';
			
		}
		$('#node_provin_tbody').html(html);
	}
}

function setIcpData(data){
	if(data && data.length > 0){
		var html = '';
		for(var i=0; i<data.length; i++){
			var domain = 'icpList[' + i + '].domain';
			var icp = 'icpList[' + i + '].icp';
			html += '<tr>'
				+ '<td>'
				+ '<span>'+ (i+1) +')</span>'
				+ '</td>'
				+ '<td>'
				+ '<input type="text" class="form-control input-sm" name="'+domain+'" value="'+data[i].domain+'" readonly/>'
				+ '<span>、</span>'
				+ '</td>'
				+ '<td>'
				+ '<input type="text" class="form-control input-sm" name="'+icp+'" value="'+data[i].icp+'" readonly/>'
				+ '</td>'
				+ '</tr>';
		}
		$('#cname_tbody').html(html);
	}
}

/**
 * form 数据填充
 */
function fillFormData(form, obj) {
	var formEL = $(form);
	$.each(obj, function(index, item) {
	   formEL.find("[name=" + index + "]").val(item);
	});
}

/**
 * 返回按钮
 * @returns
 */
function backView(){
	var userId = $('#userId').val();
	window.location.replace("evalResultInfo?userId="+userId);
}

function updateMolData(){
	$.ajax({
		type : "POST",
		url : "reportMol/upCdnMolData",
		data : $("#queryForm").serialize(),
		traditional: true,
		dataType : "json",
		success : function(data) {
			if (data.flag) {
				layer.alert("修改成功！", {icon : 3,offset: '100px'});
			} else {
				layer.alert("修改失败！", {icon : 3,offset: '100px'});
			}
		},
		error : function(data) {
			layer.closeAll();
		}
	});
}
